package IC.Symbols;

import IC.AST.ASTNode;
import IC.Types.Type;

/**
 * Created by IntelliJ IDEA.
 * User: nimrod
 * Date: 10/01/12
 * Time: 14:08
 * To change this template use File | Settings | File Templates.
 */
public class Symbol {
    private String name;
    private Type type;
    private Kind kind;
    
    private int initDepth;
    private Object initContext;
    private int symbolOffset;

    private String lirName;
    
    private ASTNode node;

    public Symbol(String name, Type type, Kind kind, ASTNode node) {
        this.name = name;
        this.type = type;
        this.kind = kind;
        this.node = node;

        this.initDepth = Integer.MAX_VALUE;
    }

    public String getName() {
        return name;
    }

    public Type getType() {
        return type;
    }

    public Kind getKind() {
        return kind;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        this.writeAsString(sb);

        return sb.toString();
    }

    public void writeAsString(StringBuilder sb) {
        sb.append(kind.getName()).append(": ");
        switch (this.kind) {
            case Class:
                sb.append(this.name);
                break;
            case StaticMethod:
            case VirtualMethod:
                sb.append(this.name).append(" ");
                sb.append(this.type.getName());
                break;
            case Field:
            case Parameter:
            case Var:
                sb.append(this.type.getName()).append(" ");
                sb.append(this.name);
                break;
            case ReturnVar:
            case This:
                sb.append(this.type.getName());
                break;
        }
    }

    public Object getInitContext() {
        return initContext;
    }

    public void setInitContext(Object initContext) {
        this.initContext = initContext;
    }

    public int getInitDepth() {
        return initDepth;
    }

    public void setInitDepth(int initDepth) {
        this.initDepth = initDepth;
    }

    public int getSymbolOffset() {
        return symbolOffset;
    }

    public void setSymbolOffset(int symbolOffset) {
        this.symbolOffset = symbolOffset;
    }

    public String getLirName() {
        return lirName;
    }

    public void setLirName(String lirName) {
        this.lirName = lirName;
    }

    public ASTNode getNode() {
        return node;
    }
}
